
//
//  JoinDuoBaoView.m
//  1243
//
//  Created by apple on 16/7/4.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "JoinDuoBaoView.h"




@interface JoinDuoBaoView ()<UITextFieldDelegate>

@end

@implementation JoinDuoBaoView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        UIView *backView = [[UIView alloc]initWithFrame:frame];
        backView.backgroundColor = [UIColor blackColor];
        backView.alpha = 0.5;
        
        UITapGestureRecognizer *tapRecognizerWeibo=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeView:)];
        [backView addGestureRecognizer:tapRecognizerWeibo];
        
        UIView *whiteView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT - 304, WIDTH, 240)];
        whiteView.backgroundColor = [UIColor whiteColor];
        
        self.pic = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, WIDTH/3, 70)];
        self.pic.backgroundColor = [UIColor redColor];
        
        self.titleLB = [[UILabel alloc]initWithFrame:CGRectMake(20 + WIDTH/3, 50, 120, 15)];
        self.titleLB.font = [UIFont systemFontOfSize:13];
        self.titleLB.text = @"经典复古皮质机械表";
        
        self.phaseLB = [[UILabel alloc]initWithFrame:CGRectMake(20 +WIDTH/3, 65, 100, 15)];
        self.phaseLB.font = [UIFont systemFontOfSize:11];
        self.phaseLB.text = @"第XXX期";
        
        self.numLB = [[UILabel alloc]initWithFrame:CGRectMake(10, 80, 100, 20)];
        self.numLB.font = [UIFont systemFontOfSize:12];
        self.numLB.text = @"清选择参与次数";
        self.numLB.textColor = [UIColor grayColor];
        
        //输入框
        self.numTF = [[UITextField alloc]initWithFrame:CGRectMake(60, 110, WIDTH - 120, 30)];
        self.numTF.textAlignment = NSTextAlignmentCenter;
        self.numTF.textColor = [UIColor blackColor];
        self.numTF.placeholder = @"手动输入";
        self.numTF.layer.borderWidth = 1;
        self.numTF.layer.borderColor = [[UIColor blackColor] CGColor];
        self.numTF.delegate = self;
        
        //10
        self.tenBT = [UIButton buttonWithType:UIButtonTypeCustom];
        self.tenBT.frame = CGRectMake(10, 150, (WIDTH - 40)/3, 30);
        self.tenBT.layer.borderWidth = 1;
        self.tenBT.layer.borderColor = [[UIColor grayColor] CGColor];
        [self.tenBT setTitle:@"10次" forState:UIControlStateNormal];
        [self.tenBT setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.tenBT addTarget:self action:@selector(tenAction:) forControlEvents:UIControlEventTouchUpInside];
        
        //20
        self.tweBT = [UIButton buttonWithType:UIButtonTypeCustom];
        self.tweBT.frame = CGRectMake(20 + (WIDTH - 40)/3, 150, (WIDTH - 40)/3, 30);
        self.tweBT.layer.borderWidth = 1;
        self.tweBT.layer.borderColor = [[UIColor grayColor] CGColor];
        [self.tweBT setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.tweBT setTitle:@"20次" forState:UIControlStateNormal];
        [self.tweBT addTarget:self action:@selector(tweAction:) forControlEvents:UIControlEventTouchUpInside];
        
        //50
        self.fifBT = [UIButton buttonWithType:UIButtonTypeCustom];
        self.fifBT.frame = CGRectMake(30 + ((WIDTH - 40)/3)*2, 150, (WIDTH - 40)/3, 30);
        self.fifBT.layer.borderWidth = 1;
        self.fifBT.layer.borderColor = [[UIColor grayColor] CGColor];
        [self.fifBT setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.fifBT setTitle:@"50次" forState:UIControlStateNormal];
        [self.fifBT addTarget:self action:@selector(fifAction:) forControlEvents:UIControlEventTouchUpInside];
        
        self.lineLB = [[UILabel alloc]initWithFrame:CGRectMake(0, 190, WIDTH, 1)];
        self.lineLB.backgroundColor = [UIColor grayColor];
        
        self.moneyLB = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH - WIDTH/3 - 70, 191, 70, 49)];
        self.moneyLB.textColor = [UIColor orangeColor];
        self.moneyLB.font = [UIFont systemFontOfSize:11];
        self.moneyLB.text = @"合计:¥5.00";
        
        self.affrimBT = [UIButton buttonWithType:UIButtonTypeCustom];
        self.affrimBT.backgroundColor = [UIColor blueColor];
        self.affrimBT.frame = CGRectMake(WIDTH - WIDTH/3, 191, WIDTH/3, 50);
        [self.affrimBT addTarget:self action:@selector(xiadanAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.affrimBT setTitle:@"立即夺宝" forState:UIControlStateNormal];
        
        [self addSubview:backView];
        [self addSubview:whiteView];
        [whiteView addSubview:self.titleLB];
        [whiteView addSubview:self.phaseLB];
        [whiteView addSubview:self.numLB];
        [whiteView addSubview:self.numTF];
        [whiteView addSubview:self.tenBT];
        [whiteView addSubview:self.tweBT];
        [whiteView addSubview:self.fifBT];
        [whiteView addSubview:self.pic];
        [whiteView addSubview:self.lineLB];
        [whiteView addSubview:self.affrimBT];
        [whiteView addSubview:self.moneyLB];
        
    }
    return self;
}

- (void)tenAction:(UIButton *)sender {
    sender.backgroundColor = [UIColor grayColor];
    self.tweBT.backgroundColor = [UIColor whiteColor];
    self.fifBT.backgroundColor = [UIColor whiteColor];
    self.moneyLB.text = [NSString stringWithFormat:@"合计:¥%d.00",5*10];
    self.numTF.text = @"10";
    NSLog(@"10");
}

- (void)tweAction:(UIButton *)sender {
    sender.backgroundColor = [UIColor grayColor];
    self.tenBT.backgroundColor = [UIColor whiteColor];
    self.fifBT.backgroundColor = [UIColor whiteColor];
    self.moneyLB.text = [NSString stringWithFormat:@"合计:¥%d.00",5*20];
    self.numTF.text = @"20";
    NSLog(@"20");
}

- (void)fifAction:(UIButton *)sender {
    sender.backgroundColor = [UIColor grayColor];
    self.tweBT.backgroundColor = [UIColor whiteColor];
    self.tenBT.backgroundColor = [UIColor whiteColor];
    self.moneyLB.text = [NSString stringWithFormat:@"合计:¥%d.00",5*50];
    self.numTF.text = @"50";
    NSLog(@"50");
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    self.moneyLB.text = [NSString stringWithFormat:@"合计:¥%ld.00",5 * [textField.text integerValue]];
    
    [textField resignFirstResponder];
    return YES;
}

- (void)removeView:(UITapGestureRecognizer *)sender {
    [self removeFromSuperview];
}

- (void)xiadanAction:(UIButton *)sender {

    if (self.dingdanBlock) {
        self.dingdanBlock(self.numTF.text,self.moneyLB.text,self.titleLB.text,self.phaseLB.text);
    }
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
